home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / timing.arc / TIMERS.BAS < prev    next >
BASIC Source File  |  1987-10-01  |  3KB  |  71 lines

  1. '$MODULE: 'TIMERS'
  2. '$INCLUDE: 'fnCTICKS.def'
  3.  
  4. '*****************************************************************************
  5. '*** DELAY - performs a "hard" delay.
  6. SUB DELAY (HUN.SCNDS!) STATIC
  7. '$MODULE: 'DELAY'
  8. 'input:  an integer representing the number of hundredth-seconds to delay
  9. 'delay == input: HUN.SCNDS! = hundredths of seconds
  10.  
  11. '$INCLUDE: 'TICKS.def'
  12.  
  13. START.TIME! = FNCTICKS(0)                      ' mark the current time
  14. ENDING.TIME!= FNCTICKS(HUN.SCNDS!)            ' mark the ending time
  15. IF ENDING.TIME! < START.TIME! THEN
  16.         ENDING.TIME! = ENDING.TIME! + TICKS.PER.DAY!
  17. end if
  18.  
  19. do
  20.         CURRENT.TIME! = FNCTICKS(0)                    ' mark the current time
  21.         if current.time! < start.time! then
  22.                 current.time! = current.time! + ticks.per.day!
  23.         end if
  24. loop until current.time! >= ending.time!
  25.  
  26. EXIT SUB
  27. END SUB
  28. '*** end of DELAY
  29. '*****************************************************************************
  30.  
  31. '*****************************************************************************
  32. '*** BGDELAY - performs a background delay, returning control to the caller
  33. '***    after each check so that the caller may be doing something
  34. '***    while waiting.
  35. SUB BGDELAY (HUN.SCNDS!,HUN.SCNDS.TO.GO!,STATUS%) STATIC
  36. '$MODULE: 'bgDELAY'
  37. 'input:  an integer representing the number of hundredth-seconds to delay
  38. 'delay == input: HUN.SCNDS! = hundredths of seconds
  39. '        output: HUN.SCNDS.TO.GO! = hundredths of seconds until timeout
  40. '        output: STATUS%   = 0 - delay is complete; 1 - delay is continuing
  41.  
  42. '$INCLUDE: 'TICKS.def'
  43.  
  44. STATIC START.TIME!,ENDING.TIME!
  45. IF STATUS% = 0 THEN             'entering for the first time this request
  46.         START.TIME! = FNCTICKS(0)                  ' mark the current time
  47.         ENDING.TIME! = FNCTICKS(HUN.SCNDS!)        ' mark the ending time
  48.         IF ENDING.TIME! < START.TIME! THEN
  49.                 ENDING.TIME! =ENDING.TIME! + TICKS.PER.DAY!
  50.         end if
  51. end if
  52.  
  53. CURRENT.TIME! = FNCTICKS(0)
  54. IF CURRENT.TIME! < START.TIME! THEN
  55.         CURRENT.TIME! = CURRENT.TIME! + TICKS.PER.DAY!
  56. end if
  57. TICKS.LEFT! = ENDING.TIME! - CURRENT.TIME!       'calculate ticks left to go
  58. HUN.SCNDS.TO.GO! = (TICKS.LEFT!*100)/TICKS.PER.SEC! ' see Tech.Ref.
  59.  
  60. IF TICKS.LEFT! > 0 THEN
  61.         status%=1                           ' time has NOT run out
  62. else
  63.         status%=0                           ' delay is complete
  64. end if
  65.  
  66. exitsub:
  67. EXIT SUB
  68. END SUB
  69. '*** end of BGDELAY
  70. '*****************************************************************************
  71.